<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>类型管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card>
            <el-transfer v-model="value" :data="data" :titles="['允许展示', '禁止展示']"  @change="changeCategoryState"></el-transfer>
        </el-card>
    </div>
</template>

<script>
export default {
  data () {
    return {
      data: [],
      value: [],
      changeInfo: {
        drection: '',
        categoryIds: []
      }
    }
  },
  created () {
    this.getCategory()
  },
  methods: {
    async getCategory () {
      const { data: res1 } = await this.$axios.get('admin/getcategorybystate/' + 1)
      const { data: res2 } = await this.$axios.get('admin/getcategorybystate/' + 2)
      this.data = res1.data
      this.value = res2.data
    },
    async changeCategoryState (value, direction, movedKeys) {
      console.log(value, direction, movedKeys)
      this.changeInfo.direction = direction
      this.changeInfo.categoryIds = movedKeys
      const { data: res } = await this.$axios.post('admin/updatecategorystate', this.changeInfo)
      if (res.code !== 200) {
        return this.$message.error(res.msg)
      } else {
        this.$message.success(res.msg)
      }
      this.getCategory()
    }
  }
}
</script>

<style>

</style>
